package com.ruoyi.web.controller.revenue;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WaterPriceconfig;
import com.ruoyi.system.service.IWaterPriceconfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 价格设置Controller
 *
 * @author ruoyi
 * @date 2025-09-16
 */
@RestController
@RequestMapping("/revenue/priceConfig")
public class WaterPriceconfigController extends BaseController
{
    @Autowired
    private IWaterPriceconfigService waterPriceconfigService;

    /**
     * 查询价格设置列表
     */
    @PreAuthorize("@ss.hasPermi('revenue:priceConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(WaterPriceconfig waterPriceconfig)
    {
        startPage();
        List<WaterPriceconfig> list = waterPriceconfigService.selectWaterPriceconfigList(waterPriceconfig);
        return getDataTable(list);
    }

    /**
     * 导出价格设置列表
     */
    @PreAuthorize("@ss.hasPermi('revenue:priceConfig:export')")
    @Log(title = "价格设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WaterPriceconfig waterPriceconfig)
    {
        List<WaterPriceconfig> list = waterPriceconfigService.selectWaterPriceconfigList(waterPriceconfig);
        ExcelUtil<WaterPriceconfig> util = new ExcelUtil<WaterPriceconfig>(WaterPriceconfig.class);
        util.exportExcel(response, list, "价格设置数据");
    }

    /**
     * 获取价格设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('revenue:priceConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(waterPriceconfigService.selectWaterPriceconfigById(id));
    }

    /**
     * 新增价格设置
     */
    @PreAuthorize("@ss.hasPermi('revenue:priceConfig:add')")
    @Log(title = "价格设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WaterPriceconfig waterPriceconfig)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        waterPriceconfig.setCreateBy(loginUser.getUsername());
        waterPriceconfig.setCompanyId(getDeptId() + "");
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmm");
        String priceCode = df.format(new Date());
        waterPriceconfig.setPriceCode(priceCode);
        return toAjax(waterPriceconfigService.insertWaterPriceconfig(waterPriceconfig));
    }

    /**
     * 修改价格设置
     */
    @PreAuthorize("@ss.hasPermi('revenue:priceConfig:edit')")
    @Log(title = "价格设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WaterPriceconfig waterPriceconfig)
    {
        return toAjax(waterPriceconfigService.updateWaterPriceconfig(waterPriceconfig));
    }

    /**
     * 删除价格设置
     */
    @PreAuthorize("@ss.hasPermi('revenue:priceConfig:remove')")
    @Log(title = "价格设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(waterPriceconfigService.deleteWaterPriceconfigByIds(ids));
    }
}
